﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNG.LIB.Controls;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Web.UI.HtmlControls;
using System.Data;

public partial class AdminPortal_Controls_SanPham_inc_ProductImages : System.Web.UI.UserControl
{
    TblHinhAnhSanPhamManager _TblHinhAnhSanPhamManager = new TblHinhAnhSanPhamManager();
    int IDSanPham = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try { IDSanPham =Convert.ToInt32( Request.QueryString["id"].Trim()); }
            catch { IDSanPham = 0; }

            LoadDataToGrid(IDSanPham);
        }
    }
    
    private void LoadDataToGrid(int _IDSP)
    {
        //DataTable dt = _TblHinhAnhSanPhamManager.be_selectToGridView(_TblHinhAnhSanPhamEntity);
        DataTable dt = _TblHinhAnhSanPhamManager.SelectByIdsanPhamRDT(_IDSP);
        if (dt != null && dt.Rows.Count > 0)
        {
            dgvListProductImage.DataSource = dt;
            dgvListProductImage.DataBind();
            lblTotalRecord.Text = dt.Rows.Count.ToString();
        }
    }

    protected void dgvListProductImage_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataRowView r = (DataRowView)e.Row.DataItem;

        Image imgUpdate = (Image)e.Row.FindControl("imgUpdate");

        Image delImg = (Image)e.Row.FindControl("delImg");

        HyperLink lnkImage = (HyperLink)e.Row.FindControl("lnkImage");

        ThumbnailImages ThumbnailImages1 = (ThumbnailImages)e.Row.FindControl("ThumbnailImages1");

        if (r != null && imgUpdate != null)
        {
            lnkImage.Text = r[TblHinhAnhSanPhamFields.Image.Name].ToString();
            lnkImage.NavigateUrl = r[TblHinhAnhSanPhamFields.Image.Name].ToString();

            if (r[TblHinhAnhSanPhamFields.TrangThai.Name].ToString().Equals("True"))
                imgUpdate.ImageUrl = "~/AdminPortal/Images/Icon/tree_dnd_yes.png";
            else
                imgUpdate.ImageUrl = "~/AdminPortal/Images/Icon/tree_dnd_no.png";
            imgUpdate.Attributes.Add("onclick", "javascript:changeStatusProductImage('" + imgUpdate.ClientID + "','" + r[TblHinhAnhSanPhamFields.Id.Name].ToString() + "')");

            ThumbnailImages1.ImageUrl = r[TblHinhAnhSanPhamFields.Image.Name].ToString();

            delImg.Attributes.Add("onclick", "javascript:DeleteImages('" + delImg.ClientID + "','" + r[TblHinhAnhSanPhamFields.Id.Name].ToString() + "')");
        }
    }
}